package com.hbnu.exercise.net;

import java.io.*;
import java.net.Socket;

public class TcpClientDemo03
{
    public static void main(String[] args)
    {
        try
        {
            Socket socket = new Socket("127.0.0.1", 8888);

            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
            BufferedWriter out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
            BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

            String content = null;
            while ((content = bufferedReader.readLine()) != null)
            {
                if ("over".equalsIgnoreCase(content))
                    break;

                out.write(content);
                out.newLine();
                out.flush();

                String result = in.readLine();
                System.out.println("服务端返回的结果" + result);
            }

            bufferedReader.close();
            socket.close();
        } catch (IOException e)
        {
            e.printStackTrace();
        }
    }
}
